/**
 * 格式化日期时间
 * @param date 日期对象或日期字符串
 * @returns 格式化后的日期字符串 (YYYY-MM-DD HH:mm:ss)
 */
export const formatDate = (date: string | Date | undefined): string => {
  if (!date) return "";

  const d = typeof date === "string" ? new Date(date) : date;

  return d.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
    hour12: false,
  });
};

/**
 * 格式化罚时（分钟转为小时和分钟）
 * @param minutes 总分钟数
 * @returns 格式化后的时间字符串 (例如: 2h30m 或 45m)
 */
export const formatTimePenalty = (minutes: number | undefined): string => {
  if (!minutes) return "";

  const hours = Math.floor(minutes / 60);
  const remainingMinutes = minutes % 60;

  return hours ? `${hours}h${remainingMinutes}m` : `${remainingMinutes}m`;
};
